package com.example.smart.ui.activity.chat

import com.example.lib.constants.JumpConstants
import com.example.lib.extend.cleanText
import com.example.lib.extend.getIntentInt
import com.example.lib.extend.setOnDoubleClickListener
import com.example.lib.extend.stringText
import com.example.lib.extend.verticalManager
import com.example.lib.utils.statusbar.StatusBarUtils
import com.example.smart.R
import com.example.smart.adapter.home.ChatAdapter
import com.example.smart.base.ui.activity.BaseActivity
import com.example.smart.data.AiConversationData
import com.example.smart.databinding.ActivityChatBinding
import com.example.smart.utils.DisplayUtils.type

class ChatActivity : BaseActivity<ActivityChatBinding>() {

    private val mAdapter by lazy {
        ChatAdapter(this@ChatActivity)
    }

    override fun layoutID() = R.layout.activity_chat

    override fun initView() {
        StatusBarUtils.setStateAndNavigationBar(this@ChatActivity, statusBarColor = com.example.lib.R.color.translate)

        binding.Recycler.verticalManager()
        binding.Recycler.adapter = mAdapter
        val list = mutableListOf<AiConversationData>()
        list.add(AiConversationData(AiConversationData.TYPE_RECEIVE,
            AiConversationData.MSG_TEXT,
            "最近是春季防疫的时期，你们有按时接种疫苗吗"))
        list.add(AiConversationData(AiConversationData.TYPE_RECEIVE, AiConversationData.MSG_TEXT, "口蹄疫疫苗"))
        list.add(AiConversationData(AiConversationData.TYPE_RECEIVE,
            AiConversationData.MSG_TEXT,
            "还有那个四联三防疫苗、布病疫苗什么的"))
        list.add(AiConversationData(AiConversationData.TYPE_SEND, AiConversationData.MSG_TEXT, "什么？什么是布病疫苗？"))
        list.add(AiConversationData(AiConversationData.TYPE_RECEIVE, AiConversationData.MSG_TEXT, "我也不是特别清楚"))
        list.add(AiConversationData(AiConversationData.TYPE_RECEIVE,
            AiConversationData.MSG_TEXT,
            "我们可以在app上搜一下"))
        list.add(AiConversationData(AiConversationData.TYPE_SEND, AiConversationData.MSG_TEXT, "好"))
        mAdapter.type = getIntentInt(JumpConstants.ID)
        mAdapter.updateList(list)

        binding.UserName.text = when (mAdapter.type) {
            2 -> "阿尔善"
            3 -> "王四五"
            4 -> "新塔苏"
            5 -> "海日罕"
            else -> "格日勒"
        }
    }

    override fun initListener() {
        binding.Exit.setOnDoubleClickListener {
            finish()
        }

        binding.Send.setOnDoubleClickListener {
            val text = binding.Input.stringText()
            if (text.isNotEmpty()) {
                mAdapter.add(AiConversationData(AiConversationData.TYPE_SEND, AiConversationData.MSG_TEXT, text))
                binding.Recycler.smoothScrollToPosition(mAdapter.size() - 1)
                binding.Input.cleanText()
            }
        }
    }
}